package com.jinyi.wwdeng.utils.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.jinyi.wwdeng.R
import com.jinyi.wwdeng.databinding.DialogPhotoBinding

/**
 * Author : wwdeng
 * Date : 2023/8/1 15:44
 * <p>
 * 每天进步一点点
 * <p>
 * Desc : 拍照、相册选择 dialog
 */
class PhotoDialog: ProDialog {
    private lateinit var binding: DialogPhotoBinding
    private var mCallback: IDialogCallback? = null

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogPhotoBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.ivClose) //关闭
        setOnClickListener(R.id.cameraLayout) //拍照
        setOnClickListener(R.id.albumLayout) //相册选择
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        when(v!!.id){
            R.id.cameraLayout -> {
                if(mCallback != null){
                    mCallback!!.openCamera()
                }
            }
            R.id.albumLayout -> {
                if(mCallback != null){
                    mCallback!!.openAlbum()
                }
            }

        }
    }

    interface IDialogCallback {
        //打开相机
        fun openCamera()
        //打开相册
        fun openAlbum()
    }
}